# Mission 10 Temperature Check # Final code with check_baseline fix # and test data from botcore import * from time import sleep_ms BASELINE = 38.6 DEADBAND = 3.0 samples = [] def avg_list(nlist): count = len(nlist) sum = 0 i = 0 while i < count: sum = sum + nlist[i] i = i + 1 return sum / count def check_baseline(t): if t > BASELINE + DEADBAND: leds.user(0b11111111) leds.ls(0) elif t < BASELINE - DEADBAND: leds.ls(0b11111) leds.user(0) else: leds.user(0) leds.ls(0) # -- Main program -- while True: for i in range(5): bot_temp = system.temp_C() samples.append(bot_temp) if len(samples) == 5: avg = avg_list(samples) print("Avg Temp:", avg) samples.clear() check_baseline(avg) sleep_ms(200) sleep_ms(2000) for i in range(5): bot_temp = system.temp_C() samples.append(50) if len(samples) == 5: avg = avg_list(samples) print("Avg Temp:", avg) samples.clear() check_baseline(avg) sleep_ms(200) sleep_ms(2000) for i in range(5): bot_temp = system.temp_C() samples.append(30) if len(samples) == 5: avg = avg_list(samples) print("Avg Temp:", avg) samples.clear() check_baseline(avg) sleep_ms(200) sleep_ms(2000)